/*
  流动纹理线
  color 颜色
  duration 持续时间 毫秒
  img 图片
*/
function EllipsoidTopFadeMaterial(color, duration) {
  this._definitionChanged = new Cesium.Event();
  this._color = undefined;
  this._colorSubscription = undefined;
  this.color = color;
  this.duration = duration;
  this._time = (new Date()).getTime();
}
Object.defineProperties(EllipsoidTopFadeMaterial.prototype, {
  isConstant: {
    get: function () {
      return false;
    }
  },
  definitionChanged: {
    get: function () {
      return this._definitionChanged;
    }
  },
  color: Cesium.createPropertyDescriptor('color')
});
EllipsoidTopFadeMaterial.prototype.getType = function (time) {
  return 'EllipsoidTopFade';
}
EllipsoidTopFadeMaterial.prototype.getValue = function (time, result) {
  if (!Cesium.defined(result)) {
    result = {};
  }
  result.color = Cesium.Property.getValueOrClonedDefault(this._color, time, Cesium.Color.WHITE, result.color);

  result.time = (((new Date()).getTime() - this._time) % this.duration) / this.duration;
  return result;
}
EllipsoidTopFadeMaterial.prototype.equals = function (other) {
  return this === other ||
    (other instanceof EllipsoidTopFadeMaterial &&
      Cesium.Property.equals(this._color, other._color))
}
Cesium.EllipsoidTopFadeMaterial = EllipsoidTopFadeMaterial;
Cesium.Material.EllipsoidFadeType = 'EllipsoidTopFade';
Cesium.Material.EllipsoidFadeSource =
"czm_material czm_getMaterial(czm_materialInput materialInput)\n\
{\n\
    czm_material material = czm_getDefaultMaterial(materialInput);\n\
    vec2 st = materialInput.st;\n\
    vec4 colorImage = texture2D(image, vec2(fract(-(st.t + time)), st.t));\n\
    material.alpha = colorImage.a * color.a;\n\
    material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
    return material;\n\
}";
Cesium.Material._materialCache.addMaterial(Cesium.Material.EllipsoidFadeType, {
  fabric: {
    type: Cesium.Material.EllipsoidFadeType,
    uniforms: {
      color: new Cesium.Color(1.0, 0.0, 0.0, 1),
      time: 0,
      image: require('@assets/mapIcon/redTrail.png')
    },
    source: Cesium.Material.EllipsoidFadeSource
  },
  translucent: function (material) {
    return true;
  }
});

export default EllipsoidTopFadeMaterial;